﻿using System;
using System.Windows;
using System.Windows.Controls;
using GameEngine.View.Components;
using GameEngine.Model.Data;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;

namespace SilverlightClientEditor.View.Components
{
    public partial class GameThingTypesListUC : UserControl//, IThingEditorMenuView<int>
    {
        //ItemEditorMenuUC creator = new ItemEditorMenuUC();
        readonly ChildWindow childWnd;

        public GameThingTypesListUC()
        {
            InitializeComponent();
            //childWnd = new ChildWindow()
            //{
            //    Content = creator
            //};
            //creator.OnAddShapeClick += new Action<string, string, object>(delegate(string itemTypeName, string shapeType, object shapeProps)
            //{
            //    if(OnAddShapeClick!=null)
            //        OnAddShapeClick(itemTypeName, shapeType, shapeProps);
            //});
            //creator.OnRemoveShapeClick += new Action<string, string>(delegate(string itemTypeName, string shapeName)
            //{
            //    if(OnRemoveShapeClick!=null)
            //        OnRemoveShapeClick(itemTypeName, shapeName);
            //});
            //creator.OnCreateItemClick +=new Action<string>(delegate(string arg1){
            //    if (OnCreateItemClick != null)
            //        OnCreateItemClick(arg1);
            //    childWnd.Close();
            //});
            itemListBox.SelectionChanged += new SelectionChangedEventHandler(itemListBox_SelectionChanged);
        }

        void itemListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0 && OnItemTypeClick != null)
                OnItemTypeClick(e.AddedItems[0] as string);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            string buttonName = ((Button)sender).Name;
            //if (sender.Equals(addButton))
            //{
            //    if(OnAddItemClick!=null)
            //        OnAddItemClick(itemListBox.SelectedItem as string);
            //}
            //else if (sender.Equals(createButton))
            //{
            //    if (OnNewItemClick != null)
            //        OnNewItemClick();
            //}
        }

        public void ShowCreateWindow() {
            childWnd.Show();
        }
        
        #region ITileMapEditorMenuView Members

        public event Action<string, string, object> OnAddShapeClick;
        public event Action<string, string> OnRemoveShapeClick;
        public event Action<string> OnCreateItemClick;
        public event Action<string> OnAddItemClick;
        public event Action OnNewItemClick;
        public event Action<string> OnItemTypeClick;

        public void AddShapeToList(string shape) {
            //creator.AddShapeToList(shape);
        }

        public void RemoveShapeFromList(string shape) {
            //creator.RemoveShapeFromList(shape);
        }

        public void RemoveAllShapesFromList() {
            //creator.RemoveAllShapes();
        }

        public void AddTypeToList(string type) {
            itemListBox.Items.Add(type);
        }

        #endregion

        public void SetItemEditorWorldView(WorldUC world)
        {
            //creator.Initialize(world);
        }

        public event Action<string> OnCreateClick;

        public event Action<string> OnEditClick;

        public event Action<string> OnRemoveClick;

        public event Action<IThingTypeVOId> OnAddItemToWorldClick;

        /*event Action<IThingTypeVOId<int>> IThingEditorMenuView<int>.OnItemTypeClick
        {
            add { throw new NotImplementedException(); }
            remove { throw new NotImplementedException(); }
        }*/

        public event Action OnNewClick;
    }
}